package com.example.livedata.db.dao;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;

import com.example.livedata.entity.UserInfo;

import java.util.List;

@Dao
public interface UserDao {

    @Query("SELECT * FROM user")
    LiveData<List<UserInfo>> getAll();

    @Query("SELECT * FROM user WHERE uid IN (:userIds)")
    LiveData<List<UserInfo>> loadAllByIds(int[] userIds);

    @Query("SELECT * FROM user WHERE uid = (:userIds)")
    LiveData<UserInfo> getUser(String id);

    @Query("SELECT * FROM user WHERE first_name LIKE :first AND last_name LIKE :last LIMIT 1")
    LiveData<UserInfo> findByName(String first, String last);

    @Insert
    void insertAll(UserInfo... users);

    @Delete
    void delete(UserInfo user);
}
